package com.atguigu.lease.web.admin.controller.login;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.web.admin.service.LoginService;
import com.atguigu.lease.web.admin.vo.login.CaptchaVo;
import com.atguigu.lease.web.admin.vo.login.LoginVo;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserInfoVo;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserItemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "后台管理系统登录管理")
@RestController
@RequestMapping("/admin")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @Operation(summary = "获取图形验证码")
    @GetMapping("login/captcha")
    public Result<CaptchaVo> getCaptcha() {
        CaptchaVo captchaVo = loginService.setCode();
        return Result.ok(captchaVo);
    }

    @Operation(summary = "登录")
    @PostMapping("login")
    public Result<String> login(@RequestBody LoginVo loginVo) {
        String token = loginService.login(loginVo);
        return Result.ok(token);
    }

    /**
     * springmvc
     *   参数接收
     *      param  @RequestParam
     *      path   @PathVariable
     *      json   @RequestBody
     *      header @RequestHeader
     *      cookie @CookieValue
     *   数据响应
     *      页面： viewResolver string 不要被@ResponseBody return "中间部分";
     *      转发和重定向： string 不要被@ResponseBody return "forward: || redirect: ";
     *      返回json: @ResponseBody @RestController
     */
    @Operation(summary = "获取登陆用户个人信息")
    @GetMapping("info")
    public Result<SystemUserInfoVo> info(@RequestHeader("access_token") String accessToken) {
        SystemUserInfoVo systemUserInfoVo =loginService.customInfo(accessToken);
        return Result.ok(systemUserInfoVo);
    }
}